import json
import gzip
import yaml

#read the house from the json file
def read_house_from_json(json_file_path):
    # Open the file using gzip to handle compressed files
    with gzip.open(json_file_path, 'rt', encoding='utf-8') as f:
        house = json.load(f)
    return house

# New function to save house as JSON
def save_house_as_json(house, output_file_path):
    with open(output_file_path, 'w') as f:
        json.dump(house, f, indent=4)

def read_json(file_path):
    with open(file_path, 'r', encoding='utf-8') as file:
        data = json.load(file)
    return data

# to json 

def read_yaml_to_array(file_path):
    with open(file_path, 'r') as file:
        # Load the YAML file
        data = yaml.safe_load(file)
        
        # Assuming the YAML file contains a list at the top level
        if isinstance(data, list):
            return data
        else:
            raise ValueError("The YAML file does not contain a top-level list.")



if __name__ == "__main__":
    # json_file_path = 'big-dataset/train/731420-5341.json.gz'
    # out_file_path = 'big-dataset/train/731420-5341.json'
    # house = read_house_from_json(json_file_path)
    # print(house)

    # save_house_as_json(house,out_file_path)

    file_path = "config/robothor_habitat2021.yaml"
    data = read_yaml_to_array(file_path)
    print(data)